package com.chinawlx.wlxteacher.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chinawlx.wlxteacher.R;
import com.chinawlx.wlxteacher.wlx_grade;

import java.util.ArrayList;
import java.util.List;

/**
 * 班级列表适配器
 *
 * Created by wlx on 16/10/11.
 */

public class WLXClazzListAdapter extends BaseAdapter {
    private Context mContext;
    private List<wlx_grade> gradeList=new ArrayList<>();
    public WLXClazzListAdapter(Context mContext) {
        this.mContext=mContext;
    }
    public void setData(List<wlx_grade> gradeList){
        this.gradeList.clear();
        this.gradeList.addAll(gradeList);

    }
    public void addData(List<wlx_grade> gradeList){
        this.gradeList.addAll(gradeList);

    }
    @Override
    public int getCount() {
        return gradeList == null ? 0 : gradeList.size();
    }

    @Override
    public Object getItem(int position) {
        return gradeList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.fragment_clazz_list_item, null);
            TextView title = (TextView) convertView.findViewById(R.id.tv_title);
            TextView studentCount = (TextView) convertView.findViewById(R.id.tv_student_count);
            title.setText(gradeList.get(position).getTitle());
            if (gradeList.get(position).getStudent_count() > 0) {
                studentCount.setText(gradeList.get(position).getStudent_count() + "人");
            } else {
                studentCount.setText("暂无学生");
            }
        }
        return convertView;
    }
}

